<div class="templatemo-content-wrapper">
	<div class="templatemo-content">
		 
		<ul class="nav nav-tabs mytabs">
	  	 <li><a href="<?=site_url()?>/orderdate/index">下单日期列表</a></li>
	  	 <li class="active"><a href="<?=site_url()?>/orderdate/add">添加下单日期</a></li>
	  </ul>
		<div class="row">
			<div class="col-md-12">
				<div class="table-responsive">
					<h4 class="margin-bottom-15">编辑订单日期</h4>
					<p>默认周一至周五可以订餐，仅需添加需要修改的特殊日期</p>
					<form role="form" id="templatemo-preferences-form"
						onsubmit="return false;">
						<div class="row">
							<input type="hidden" name="id" id="id" value="<?=$orderdate['id']?>">
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">日期</label> <input
									readonly type="text" class="form-control" id="date" name="date" value="<?=$orderdate['date']?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="lastName" class="control-label">是否可以订餐</label> 

								<select name="type" id="type" class="form-control">
									<option value="0" <?php if($orderdate['type']==0){echo 'selected';}?>>当日可以订餐</option>
									<option value="1" <?php if($orderdate['type']==1){echo 'selected';}?>>当日不可以订餐</option>
								</select>
							</div>
						</div>
						 
						 
						 
						<div class="row templatemo-form-buttons">
							<div class="col-md-12">
								<button type="submit" class="btn btn-primary" id="submit_btn">编辑</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
$('#date').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
  $('body').on('click', '#submit_btn', function(){
  		var date = $('input[name="date"]').val();
  		var type = $('#type').val();

  		var req = /^\d{4}-\d{2}-\d{2}$/;

  		if(!req.test(date)){
  			alert('日期格式错误，请重新选择')
  			return ;
  		}

  		$.ajax({
  			url: "<?=site_url('/orderdate/save')?>",
  			type: 'post',
  			data: {
  				date: date,
  				type: type,
  				id: $('#id').val()
  			},
  			success: function(d){
				if(d.code){
					alert(d.msg);
					window.history.go(-1);
				} else {
					alert(d.msg);
				}
  			},
  			error: function(){
  		
  			},
  			dataType: 'json'
  		})


  })
</script>